package cn.green.business.entity;

import com.alibaba.fastjson.JSONObject;

import java.io.Serializable;
import java.sql.Date;

public abstract class Entity implements Serializable {

    public final static String del_flag_delete = "-1";

    public final static String del_flag_normal = "1";

    //主键-id
    protected String id;

    //删除标识符
    protected String delFlag;

    //创建时间
    protected Date createDate;

    //创建者id
    protected String creatorId;

    //修改时间
    protected Date updateDate;

    //修改者id
    protected String updaterId;

    //删除时间（逻辑）
    protected Date deleteDate;

    //删除者id
    protected String deleterId;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(String delFlag) {
        this.delFlag = delFlag;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public Date getDeleteDate() {
        return deleteDate;
    }

    public void setDeleteDate(Date deleteDate) {
        this.deleteDate = deleteDate;
    }

    public String getCreatorId() {
        return creatorId;
    }

    public void setCreatorId(String creatorId) {
        this.creatorId = creatorId;
    }

    public String getUpdaterId() {
        return updaterId;
    }

    public void setUpdaterId(String updaterId) {
        this.updaterId = updaterId;
    }

    public String getDeleterId() {
        return deleterId;
    }

    public void setDeleterId(String deleterId) {
        this.deleterId = deleterId;
    }

    /**
     * 重写toString方法,默认为生成json
     * @return
     */
    public String toString() {
        return this.toJsonString();
    }

    /**
     * 把当前对象转换成json字符串
     * @return
     */
    public String toJsonString() {
        return JSONObject.toJSONString(this);
    }

    /**
     * 重写equals方法
     * @param obj
     * @return
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == null) return false;
        if (obj instanceof Entity) {
            Entity target = (Entity) obj;
            String id = target.getId();
            if (this.id != null && this.id.equals(id)) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}
